package com.dq.Week2.day09.dict;

public class Demo01 {
    public static void main(String[] args) throws InterruptedException {
        Object o = new Object();

        synchronized (o)
        {
            System.out.println(Thread.currentThread().getName()+"开始运行了");
            System.out.println("线程已开启");

            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    synchronized (o)
                    {
                        System.out.println(Thread.currentThread().getName()+"开始运行了");
                        try {
                           Thread.sleep(2000);
                        }catch (InterruptedException e)
                        {
                                throw  new RuntimeException(e);
                        }
                        System.out.println(Thread.currentThread().getName()+"睡醒了");
                        o.notify();
                    }
                }
            });

            thread.setName("setName");
            thread.start();

            o.wait();
            System.out.println("睡醒了");
        }
    }
}
